<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>事件指令</title>
    <script src="angularjs/angular.min.js"></script>
    <link rel="stylesheet" href="bootstrap.min.css"/>
</head>
<body ng-app="doraApp">
    <form action="/test" ng-controller="ctrl" class="form-group" ng-submit="add1($event)">
        <input type="text" class="form-control" ng-model="body"/>
        <button type="submit" class="btn btn-default">提交</button>
        <button type="button" class="btn btn-primary" ng-click="add()">Test</button>
        <br/>
        <hr/>
        <ul class="list-group">
            <li class="list-group-item" ng-repeat="post in posts">{{post}}</li>
        </ul>
    </form>

    <script>
        angular.module("doraApp",[])
                .controller("ctrl",function($scope){
                    $scope.posts = [];
                    $scope.add = function () {
                        $scope.posts.push($scope.body);
                        $scope.body = "";
                    }

                    $scope.add1 = function (event) {
                        event.preventDefault();
                        $scope.posts.push($scope.body);
                        $scope.body = "";
                    }
                })
    </script>
</body>
</html>